package com.waimai.demo.back;

import com.waimai.demo.Controller.EmployeeController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.lang.annotation.Annotation;
import java.sql.SQLClientInfoException;
import java.sql.SQLIntegrityConstraintViolationException;

@RestControllerAdvice(annotations = {RestController.class, Controller.class})
@ResponseBody
@Slf4j
public class exceptionHandler {
    @ExceptionHandler(SQLIntegrityConstraintViolationException.class)
    public R exceptionhandler(SQLIntegrityConstraintViolationException ex) {
        log.info("捕获异常：{}" + ex.getMessage());
        return R.error("未知错误失败");
    }

    @ExceptionHandler(runtimeException.class)
    public R custexception(runtimeException ex) {
        log.info("捕获异常：{}" + ex.getMessage());
        return R.error(ex.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public R exception(Exception exception) {
        log.info("异常为" + exception);
        return R.error("出问题了家人");
    }
}
